//=============================================================================
// TF Torso Bomb, Can commit suicide or it just blows when you die
//=============================================================================
class TFTorsoBomb extends TFPowerups;

var vector oldPos;
var float lastduck;
var int dcount;
var bool ducked;

replication
{
    reliable if( Role==ROLE_Authority )
	oldPos, dcount, lastduck, ducked;
}

state Activated
{
	function BeginState()
	{
		initialstate='activated';
        if(instigator==none) instigator=pawn(owner);
        Owner.PlaySound(ActivateSound,SLOT_Interface,3);
        bActive = true;

        settimer(0.5, true);
	}

    function Tick(float dt)
    {
        if(playercontroller(instigator.Controller)!=none)
        {
            if(!ducked && playercontroller(instigator.Controller).bDuck==1)
            {
                 ducked=true;

                 if(level.TimeSeconds<lastDuck+0.4) dcount++;

                 lastDuck=level.TimeSeconds;
            }
            else if(ducked && playercontroller(instigator.Controller).bDuck==0)
            {
                ducked=false;
            }

            if(level.TimeSeconds>lastDuck+0.4) dcount=0;

            if(dcount>=5)
            {
                instigator.TakeDamage( 99999, none, Location, 50000*vect(16375,0,0), class'Taskforces.DamTypeTBomb');
                gotostate('');
            }
        }
    }

    function Timer()
    {
        if(instigator.Health<=20) Owner.PlaySound(sound'TFMedia.TFTBBeep',SLOT_None,1);
        oldPos=instigator.Location;
        if(instigator==none || instigator.Health<=0)
        {
            instigator.TakeDamage( 99999, none, Location, 50000*vect(16375,0,0), class'Taskforces.DamTypeTBomb');
            gotostate('');
        }
    }

	function EndState()
	{
        local vector loc;
        local int i;
        local rotator rot;

        if(instigator==none) loc=oldPos;
        else loc=instigator.Location;

        Instigator.PlaySound(sound'TFMedia.TFTBExp',SLOT_None,7);

        rot.Pitch=16375;

        Spawn(class'LavaDeath',,,loc);
        Spawn(class'Taskforces.TFTBSparks',,,loc,rot);

        HurtRadius(300, 750, class'Taskforces.DamTypeTBomb', 50000, loc);

        for(i=0; i<25; i++)
        {
            rot=instigator.GetViewRotation();
            rot.Pitch+=16375*frand()-8187;
            rot.Yaw+=16375*frand()-8187;
            rot.Roll+=16375*frand()-8187;

            Spawn(class'Taskforces.TFTBShrapnel',,,loc,rot);
        }

        bActive = false;
	}

	function Activate()
	{

	}
}

defaultproperties
{
     bAutoActivate=True
     bActivatable=True
     ActivateSound=Sound'TFMedia.Equipment.TFTBActiv'
     bReplicateInstigator=True
     SkillCost=50
}
